package com.weather.pm.activity;

import com.weather.pm.R;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.RelativeLayout;

import cn.jpush.android.api.JPushInterface;


public class MsgSettingActivity extends UmBaseActivity implements OnClickListener {
	boolean isReceive;
	CheckBox layout;
	float x1;
	float x2;
	 Button button;
	 SharedPreferences preferences;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.msg_setting);
		findViewById(R.id.imb_back).setOnClickListener(this);
		button =  (Button)findViewById(R.id.radioButton1);
	    layout = (CheckBox)findViewById(R.id.ll_bg);
	   
	    preferences = this.getSharedPreferences("CitySP", Context.MODE_PRIVATE);
	    
	

	    
	    layout.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				
				x1 = 6;
				x2 =  76;
				
				setButton(isChecked);
				
				if(isChecked){
					JPushInterface.stopPush(MsgSettingActivity.this);
				}else{
					JPushInterface.resumePush(MsgSettingActivity.this);
				}
				
				Editor editor = preferences.edit();
				editor.putBoolean("isReceive",!isChecked);
				editor.commit();
				
			}

			
		});
	   
	    
	}
	private void setButton(boolean isChecked) {
		if(isChecked){
			Animation animation = AnimationUtils.loadAnimation(MsgSettingActivity.this,R.anim.btn_toright);
			/*animation.setDuration(250);
			animation.setFillAfter(true);*/
			button.startAnimation(animation);
			layout.setBackgroundResource(R.drawable.msg_btn_ll_shap_2);
		}else {
		/*	x2 = button.getX();
			x1 = layout.getWidth()-button.getWidth();*/
			Animation animation2 =AnimationUtils.loadAnimation(MsgSettingActivity.this, R.anim.btn_tolift);
			/*animation2.setDuration(250);
			animation2.setFillAfter(true);*/
			button.startAnimation(animation2);
			layout.setBackgroundResource(R.drawable.msg_btn_ll_shap);
		}
	}
@Override
public void onResume() {
	 isReceive  = preferences.getBoolean("isReceive", true);
	layout.setChecked(!isReceive);
	super.onResume();
}

	@Override
	public void onClick(View v) {
		finish();
	}

}
